define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Transferdetail,$stateParams, GoPage,$ionicSlideBoxDelegate,GoDialog) {

		//接受参数
		$scope.good_id = $stateParams.good_id;
		$scope.store_id = 0;
		//加载数据
		$scope.init_data = function() {
			Transferdetail.detail($scope.good_id,function(data) {
				$scope.detail = data;
				$scope.store_id = data.store_id;
				console.log(data)
				$ionicSlideBoxDelegate.$getByHandle('advs-handle').update(); //解决无法加载
			    $ionicSlideBoxDelegate.$getByHandle('advs-handle').loop(true); //循环
			});
		}
		$scope.init_data(); //必须在定义之后

		//跳转到商品详情页--通过/:id来跳转到相应的tab页面
		$scope.onshow_productInfo = function(index){//因为id是从上一个页面传过来的，所以直接把该id传给下一个页面即可
			GoPage.go_states("product_info",{"id":index,"isTransfer":true,"goods_id":$scope.good_id});
		}
		//跳转到店铺
		$scope.onshow_first = function(index,store_id){
			GoPage.go_states("first",{"index":index,"store_id":store_id});
		}
		//收藏店铺
		$scope.addStroe = function(){
			Transferdetail.addstore($scope.store_id,function(data) {
				if(data.success){
					GoDialog.toast("收藏店铺成功！");
				}else{
					GoDialog.toast(data.msg);
				}
			});
		}
		//收藏商品
		$scope.addGoods = function(){
			Transferdetail.addgoods($scope.good_id,function(data) {
				if(data.success){
					GoDialog.toast("收藏商品成功！");
				}else{
					GoDialog.toast(data.msg);
				}
			});
		}
		


	}

	controller.$inject = ['$scope', 'Transferdetail','$stateParams', 'GoPage','$ionicSlideBoxDelegate',"GoDialog"];

	return app.registerController("transferdetailctrl",controller);
});